package com.jt.www.util;

import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class EmaySMSUtil {

    public static final String CDKEY = "8SDK-EMY-6699-SEYQO";
    public static final String PASSWORD = "624711";
    public static final String HOST_URL = "http://sdk999in.eucp.b2m.cn:8080/sdkproxy/";
    public static final String REGIST_URI = "regist.action";
    public static final String QUERYBALANCE_URI = "querybalance.action";
    public static final String SENDSMS_URI = "sendsms.action";
    public static final String SENDTIMESMS_URI = "sendtimesms.action";


    /*
     * 可以用！！！
     *
     * phone	手机号码（最多1000个），多个用英文逗号(,)隔开。
     * message	短信内容（UTF-8编码）（最多500个汉字或1000个纯英文）。
     * addserial	附加号（最长10位，可置空）。
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public static String sendSMS(String phoneNos, String message) throws URISyntaxException {
        String param = "cdkey=" + CDKEY + "&"
                + "password=" + PASSWORD + "&"
                + "phone=" + phoneNos + "&"
                + "message=" + message + "&"
                + "addserial=";
        Map paramMap = new HashMap();
        paramMap.put("url", HOST_URL + SENDSMS_URI);
        paramMap.put("param", param);
        Map resultMap = HttpClientUtil.doHttpGet(paramMap);
        Object error = resultMap.get("error");
        return error.toString();
    }


    @SuppressWarnings({"rawtypes", "unchecked"})
    public static String queryBalance() throws URISyntaxException {
        String param = "cdkey=" + CDKEY + "&password=" + PASSWORD;
        Map paramMap = new HashMap();
        paramMap.put("url", HOST_URL + QUERYBALANCE_URI);
        paramMap.put("param", param);
        Map resultMap = HttpClientUtil.doHttpGet(paramMap);

        return JsonUtil.object2Json(resultMap);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public static String regist() throws URISyntaxException {
        String param = "cdkey=" + CDKEY + "&password=" + PASSWORD;
        Map paramMap = new HashMap();
        paramMap.put("url", HOST_URL + REGIST_URI);
        paramMap.put("param", param);
        Map resultMap = HttpClientUtil.doHttpGet(paramMap);
        return JsonUtil.object2Json(resultMap);
    }

    public static void main(String[] args) throws URISyntaxException {
        String code = String.valueOf((int) Math.round(Math.random() * (9999 - 1000) + 1000));
        String result = sendSMS("15811408006", "【江泰】 您购买的\"安•康保护伞\"产品（保单号：90168440101150002330，保险止期：2016-09-19）即将到期，为保障您的保险权益，请您及时登录我学保公众号续保。");
        System.out.println(result);
    }
}